package com.yaosheng.thread.interview;

import java.util.concurrent.locks.LockSupport;

/**
 * Created by yaosheng on 2021/7/6.
 */
public class LockSupportView {

    static Thread t1 = null,t2 = null;

    public static void main(String[] args) {

        char[] aI = "1234567".toCharArray ();
        char[] aC = "ABCDEFG".toCharArray ();

        t1 = new Thread ( () -> {
            for(char c : aI){
                System.out.println (c);
                LockSupport.unpark (t2);   //唤醒t2线程
                LockSupport.park ();     //阻塞t1线程
            }
        },"t1");

        t2 = new Thread ( () -> {
            for(char c : aC){
                LockSupport.park ();     //阻塞t2线程
                System.out.println (c);
                LockSupport.unpark (t1);   //唤醒t1线程
            }
        },"t2");

        t1.start ();
        t2.start ();
    }
}
